const Router = require('@koa/router');

const { auth, hadAdminPermission } = require('@middleware/auth.middleware');

const { changePageType } = require('@middleware/tools.middleware');

const { validator } = require('./goods.middleware');

const {
  upload,
  create,
  remove,
  update,
  restore,
  getList,
  getQnToken,
} = require('./goods.controller');

const router = new Router({ prefix: '/goods' });

router.use(auth);

// 上传
router.post('/upload', hadAdminPermission, upload);

router.get('/getQnToken', hadAdminPermission, getQnToken);

router.post('/addGoods', hadAdminPermission, validator, create);

router.patch('/update', hadAdminPermission, validator, update);

router.delete('/delete/:id', hadAdminPermission, remove);

router.post('/restore', hadAdminPermission, restore);

router.get('/list', changePageType, getList);

module.exports = router;
